home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / MSG Demo 1.4.source Folder / Demo ƒ / Fades ƒ / Spiral fade.c < prev    next >
Text File  |  1994-04-15  |  3KB  |  113 lines

  1. /**********************************************************************\
  2.  
  3. File:        Spiral fade.c
  4.  
  5. Purpose:    Graphic effect to fade main window to solid pattern.
  6.             See comments below for more description.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "timing.h"
  26.  
  27. #define CorrectTime 1
  28. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  29. #define theWindowWidth (boundsRect.right-boundsRect.left)
  30.  
  31. pascal short SpiralGyraFade(Rect boundsRect, Pattern *thePattern);
  32.  
  33. /* Start in the topleft corner, facing downwards.  Copy until you hit (a) the
  34.    edge of the screen, or (b) bits you've already copied.  Then turn counter-
  35.    clockwise and do it again.  */
  36.    
  37. pascal short SpiralGyraFade(Rect boundsRect, Pattern *thePattern)
  38. {
  39.     int                stop,sbottom,sleft,sright,iterrow,itercol,direction;
  40.     Rect            source;
  41.     Boolean            everyOther;
  42.     int                BOXSIZE;
  43.     RgnHandle        boundsRgn;
  44.     
  45.     boundsRgn=NewRgn();
  46.     RectRgn(boundsRgn, &boundsRect);
  47.     BOXSIZE=theWindowHeight/15;
  48.     everyOther=FALSE;
  49.     stop=0;
  50.     sbottom=theWindowHeight/BOXSIZE-(theWindowHeight%BOXSIZE ? 0 : 1);
  51.     sleft=0;
  52.     sright=theWindowWidth/BOXSIZE-(theWindowWidth%BOXSIZE ? 0 : 1);
  53.     direction=3;
  54.     iterrow=stop;
  55.     itercol=sleft;
  56.     while ((stop<=sbottom)&&(sleft<=sright))
  57.     {
  58.         StartTiming();
  59.         source.top=iterrow*BOXSIZE;
  60.         source.bottom=source.top+BOXSIZE;
  61.         source.left=itercol*BOXSIZE;
  62.         source.right=source.left+BOXSIZE;
  63.         OffsetRect(&source, boundsRect.left, boundsRect.top);
  64.         FillRect(&source, *thePattern);
  65.         switch (direction)
  66.         {
  67.             case 0:  /* facing right */
  68.                 if (itercol==sright)
  69.                 {
  70.                     sbottom--;
  71.                     direction++;
  72.                     iterrow--;
  73.                 }
  74.                 else itercol++;
  75.                 break;
  76.             case 1:  /* facing up */
  77.                 if (iterrow==stop)   /* that reads "s top," not "stop" */
  78.                 {
  79.                     sright--;
  80.                     direction++;
  81.                     itercol--;
  82.                 }
  83.                 else iterrow--;
  84.                 break;
  85.             case 2:  /* facing left */
  86.                 if (itercol==sleft)
  87.                 {
  88.                     stop++;
  89.                     direction++;
  90.                     iterrow++;
  91.                 }
  92.                 else itercol--;
  93.                 break;
  94.             case 3:  /* facing down */
  95.                 if (iterrow==sbottom)
  96.                 {
  97.                     sleft++;
  98.                     direction=0;
  99.                     itercol++;
  100.                 }
  101.                 else iterrow++;
  102.                 break;
  103.         }
  104.         if (everyOther)
  105.             TimeCorrection(CorrectTime);
  106.         everyOther=!everyOther;
  107.     }
  108.     
  109.     DisposeRgn(boundsRgn);
  110.     
  111.     return 0;
  112. }
  113.